//
//  Notice.m
//  Contacts
//
//  Created by 武 娇 on 14-8-2.
//  Copyright (c) 2014年 李 雷川. All rights reserved.
//

#import "Notice.h"
#import "NoticeDao.h"
#import "DateMethod.h"
@implementation Notice
@synthesize ID,title,categoryID,content,time,noticeCategory;

+(Notice *)analysisNoticeWithDic:(NSDictionary *)dic{
    Notice *notice = [[Notice alloc]init];
    notice.ID = [dic[@"id"]integerValue];
    notice.title =dic[@"title"];
    notice.time =  [NSDate dateWithTimeIntervalSince1970:[dic[@"timeLong"] longLongValue]/1000.0];
//    NSLog(@"time is:%lld",[dic[@"timeLong"] longLongValue]);
//    NSLog(@"notice.time is:%@", notice.time);
    notice.content =dic[@"content"];
    return notice;
}


+(Notice *)getNoticeWithID:(NSInteger)ID{
    NoticeDao *dao = [[NoticeDao alloc]init];
    Notice *notice = [dao getNoticeWithID:ID];
    return notice;
}

+(NSArray *)getLatestNotices{
    NoticeDao *dao = [[NoticeDao alloc]init];
    NSArray *notices  =[dao getLatestNotices];
    return notices;
}

+(BOOL)saveWithNotice:(Notice *)notice{
    NoticeDao *dao = [[NoticeDao alloc]init];
    BOOL success  =[dao insertNotice:notice];
    return success;
}

+(BOOL)saveWithNotices:(NSArray *)notices{
    NoticeDao *dao = [[NoticeDao alloc]init];
     BOOL success  =[dao saveWithNotices:notices];
    return success;
}

+(BOOL)updateNoticeContent:(Notice *)notice{
    NoticeDao *dao = [[NoticeDao alloc]init];
    BOOL success  =[dao updateNoticeContent:notice];
    return success;
}
+(BOOL)clearNotice{
    NoticeDao *dao = [[NoticeDao alloc]init];
    BOOL success  =[dao clearNotice];
    return success;
}
+(NSArray *)getNoticesWithCategoryID:(NSInteger)categoryID{
    NoticeDao *dao = [[NoticeDao alloc]init];
    NSArray *notices  =[dao getNoticesWithCategory:categoryID];
    return notices;
}
@end
